package com.xywy.bloodandroid.act;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xywy.bloodandroid.R;
import com.xywy.bloodandroid.base.BaseActivity;

/**
 * 领取凭证
 */
public class AddNumSendMsgActvity extends BaseActivity {

	protected static final int REFRESH = 0;
	private TextView middle_title;
	private RelativeLayout left_img;
	private TextView tv_countdown;

	@Override
	protected void initView(Bundle savedInstanceState) {
		setContentView(R.layout.activity_send_msg);

		tv_countdown = (TextView) findViewById(R.id.tv_countdown);
		middle_title = (TextView) findViewById(R.id.middle_title);
		middle_title.setText("加号详情");
		left_img = (RelativeLayout) findViewById(R.id.left_img);

	}

	@Override
	protected void initListener() {
		left_img.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				AddNumSendMsgActvity.this.finish();
			}
		});
	}

	@Override
	protected void initData() {

		new Thread(new Runnable() {

			@Override
			public void run() {
				for (int i = 4; i > -1; i--) {
					for (int j = 60; j > -1; j--) {
						Message msg = Message.obtain();
						msg.what = REFRESH;
						msg.arg1 = i;
						msg.arg2 = j;
						handler.sendMessage(msg);
						try {
							Thread.sleep(1000);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

					}
				}

			}
		}).start();

	}

	Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {

			switch (msg.what) {
			case REFRESH:
				if (msg.arg1 == 0 && msg.arg2 == 0) {
					finish();
				} else {
					tv_countdown.setText(msg.arg1 + "分钟" + msg.arg2 + "秒后返回");
				}
				break;

			default:
				break;
			}

		};
	};

}
